<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\File;
use app\common\model\Message;
use app\common\model\Product;
use app\common\model\Spot;
use app\common\model\Trainee;
use app\common\model\xiluedu\UserVip;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {

        $spot = Spot::order('id desc')->find();
        $this->success('请求成功', compact('spot'));
    }
    /**
     * @Author LK
     * @date: 2023-10-18 
     * @ApiTitle (今日热点)
     * @ApiMethod (GET)
     * @ApiParams (name="size", type="integer", required=true, sample="", description="每页数量")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function spot()
    {
        $params = request()->param();
        extract($params);
        $lists = Spot::order('id desc')->paginate($size ? $size : 15);
        $this->success('请求成功', $lists);
    }
    /**
     * @Author LK
     * @ApiTitle (今日热点详情)
     * @ApiMethod (GET)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function spot_info()
    {
        $params = request()->param();
        extract($params);
        $lists = Spot::get($id);
        $this->success('请求成功', $lists);
    }
    /**
     * @Author LK
     * @ApiTitle (产品列表)
     * @ApiMethod (GET)
     * @ApiParams (name="size", type="integer", required=true, sample="", description="每页数量")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function product()
    {
        $params = request()->param();
        extract($params);
        $lists = Product::order('id desc')->paginate($size ? $size : 15);
        $this->success('请求成功', $lists);
    }
    /**
     * @Author LK
     * @ApiTitle (产品详情)
     * @ApiMethod (GET)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function product_info()
    {
        $params = request()->param();
        extract($params);
        $lists = Product::get($id);
        $this->success('请求成功', $lists);
    }
    /**
     * @Author LK
     * @ApiTitle (学员列表)
     * @ApiMethod (GET)
     * @ApiParams (name="size", type="integer", required=true, sample="", description="每页数量")
     * @ApiParams (name="recommend", type="integer", required=true, sample="", description="all=全部,0=不推荐,1=推荐")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function trainee()
    {
        $params = request()->param();
        extract($params);
        $trainee = new Trainee();
        if ($recommend != 'all') {
            $trainee->where('recommend', $recommend);
        }
        $lists = $trainee->order('weigh desc,id desc')->paginate($size ? $size : 15);
        $this->success('请求成功', $lists);
    }
    /**
     * @Author LK
     * @ApiTitle (学员详情)
     * @ApiMethod (GET)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function trainee_info()
    {
        $params = request()->param();
        extract($params);
        $lists = Trainee::get($id);
        $this->success('请求成功', $lists);
    }
    /**
     * @Author LK
     * @ApiTitle (资讯)
     * @ApiMethod (get)
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function msg_list()
    {
        $lists = Message::paginate(100);
        $this->success('', $lists);
    }

    /**
     * @Author LK
     * @ApiTitle (资讯详情)
     * @ApiMethod (get)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="ID")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function msg_info()
    {
        $param = request()->param();
        extract($param);
        $data = Message::get($id);
        $this->success('', $data);
    }

    /**
     * @Author LK
     * @ApiTitle (资料)
     * @ApiMethod (get)
     * @ApiParams (name="type", type="integer", required=true, sample="", description="0=普通，1=VIP")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function file_list()
    {
        $param = request()->param();
        extract($param);
        $lists = File::where('is_charge', $type)->paginate();
        foreach ($lists as $v) {
            if ($v['is_charge'] == 1) {
                if ((!$this->auth->isLogin() || UserVip::isVip($this->auth->id) == 0)) {
                    $v->file = '';
                }
            }
        }
        $this->success('', $lists);
    }
    /**
     * @Author LK
     * @ApiTitle (资料详情)
     * @ApiMethod (get)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="ID")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function file_info()
    {
        $param = request()->param();
        extract($param);
        $data = File::get($id);
        if ($data['is_charge'] == 1) {
            if (!$this->auth->isLogin() || UserVip::isVip($this->auth->id) == 0) {
                $data->file = '';
            }
        }
      
        $this->success('', $data);
    }
}
